/**
 * Created by yangfakuan on 2018/10/27.
 */
//倒计时 | TOOL
function CountDown (element,count) {
    var _time;
    var e = element;
    var a = $(e.find("a").get(0));
    var c = count;
    var _that = this;

    e.attr("disabled","disabled");
    e.addClass("auth_code_grey");

    _that.down = function () {

        if(!c) {
            clearTimeout(_time);
            e.removeAttr("disabled");
            e.removeClass("auth_code_grey");
            a.html("重新获取" );
            return false;
        }

        e.attr("intervaltime", c);
        a.html("重新获取 (" + c +")" );
        c -- ;

        _time = setTimeout(function () {
            _that.down();
        }, 1000);
    };

}

//封装ajax
function AjaxHandler(_interface, type, data, sync) {

    this.url = localHttps + _interface + "?reflushCode=" + Math.random();
    this.type = type;
    this.data = data;
    this.sync = sync;

    this.handler = function (beforeSend, success,error, complete) {
        $.ajax({
            url: this.url,
            type: this.type,
            data:this.data,
            beforeSend: beforeSend,
            success: success,
            complete: complete,
            error: error,
            sync: this.sync
        });
    }
}

//Ajax服务 | SERVICE
function ajaxService(_interface, type, data,beforeSend, success, error, complete) {

    var securityAjax = new AjaxHandler(_interface, type, data);
    securityAjax.handler(beforeSend, success, error, complete);

}

//封装绑定事件 | TOOL
function BindEvent () {

    this.handler = function (element, event, callback) {

        var id =  $("#"+ element +"");

        if(callback !== undefined){

            id.on(event, callback);
            return ;
        }

        return id;
    }
}

